﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Clipper.Model;

namespace Communication
{
    public class TransportControl : ControlBase
    {
        #region 
        /// <summary>
        /// CanID
        /// </summary>
        public Int16 CanID
        {
            get
            {
                return Int16.Parse(mCanId.ToString());
            }
        }
        #endregion

        #region 滑轨，与孵育仓垂直的滑轨
        string mHome, mLPosition, mRPosition, mGo;
        string mPosition;
        /// <summary>
        /// 滑轨命令控制
        /// </summary>
        /// <param name="CanId">CanID</param>
        /// <param name="home">复位命令</param>
        /// <param name="left">左定位，第一次定位</param>
        /// <param name="right">右定位</param>
        /// <param name="go">送样(送到孵育箱小车命令)</param>
        public TransportControl(short CanId,string home,string left,string right,string go)
        {
            mCanId = CanId;
            mHome = home;
            mLPosition = left;
            mRPosition = right;
            mGo = go;
            mSCmd = new Dictionary<int, string>();
            mSCmd.Add(0, mHome);
            mSCmd.Add(1, mLPosition);
            mSCmd.Add(2, mRPosition);
            mSCmd.Add(3, mGo);
        }
        /// <summary>
        /// 洗板滑轨
        /// </summary>
        /// <param name="CanId"></param>
        /// <param name="home"></param>
        /// <param name="position"></param>
        /// <param name="go"></param>
        public TransportControl(short CanId, string home, string position, string go)
        {
            mCanId = CanId;
            mHome = home;
            mPosition = position;
            mGo = go;
            mSCmd = new Dictionary<int, string>();
            mSCmd.Add(0, mHome);
            mSCmd.Add(1, mPosition);
            mSCmd.Add(3, mGo);
        }
        /// <summary>
        /// 滑轨复位,不包括小车
        /// </summary>
        public int Home()
        {
            SendCmd(0, mHome);
            mStatus = -100;
            return 0;
        }
        /// <summary>
        /// 左定位,首先使用，调用一次进一，前四个杯子
        /// </summary>
        public int LeftPosition()
        {
            SendCmd(1, mLPosition);
            mStatus = -1;
            return 1;
        }

        /// <summary>
        /// 右定位，后四个
        /// </summary>
        public int RightPosition()
        {
            SendCmd(2, mRPosition);
            mStatus = -2;
            return 2;
        } 
        /// <summary>
        /// 洗板定位
        /// </summary>
        /// <returns></returns>
        public int WashPosition()
        {
            SendCmd(1,mPosition);
            mStatus = -1;
            return 1;
        }
        /// <summary>
        /// 送样(送到孵育箱那边)
        /// </summary>
        /// <returns>3</returns>
        public int GoIncubation()
        {
            SendCmd(3,mGo);
            mStatus = -3;
            return 3;
        }
       
        #endregion

        #region 孵育箱中的小车
        string mReset, mR1 ,mR1_1, mR2 , mR2_1 ,
            mWash1,
            mWash1_1 ,
            mSubstrate ,
            mSubstrate_1 ,
            mDetect,
            mDetect_1;
        string mWash2, mWash2_1;
        string mDS = "DS";//放反应条
        string mGS = "GS";//去反应条
        
        /// <summary>
        /// 构造孵育箱滑轨
        /// </summary>
        /// <param name="CanId"></param>
        public TransportControl()
        {
            mCanId = Can.TRANSPORT_INCUBATION_ID;
            mReset = "MV1";
            mR1 = "MV2";
            mR1_1 = "MV13";
            mR2 = "MV3";
            mR2_1 = "MV12";
            mWash1 = "MV4";
            mWash1_1 = "MV9";
            mSubstrate = "MV5";
            mSubstrate_1 = "MV10";
            mDetect = "MV6";
            mDetect_1 = "MV11";
            mWash2 = "MV14";
            mWash2_1 = "MV15";
            mSCmd = new Dictionary<int, string>();
            mSCmd.Add(0, mReset);
            mSCmd.Add(1, mR1);
            mSCmd.Add(12, mR1_1);
            mSCmd.Add(2, mR2);
            mSCmd.Add(3, mR2_1);
            mSCmd.Add(4, mWash1);
            
            mSCmd.Add(5, mWash1_1);

            mSCmd.Add(6, mSubstrate);
            mSCmd.Add(7, mSubstrate_1);
            mSCmd.Add(8, mDetect);
            mSCmd.Add(9, mDetect_1);
            mSCmd.Add(10, mDS);
            mSCmd.Add(11, mGS);
            
            mSCmd.Add(13, mWash2);
            mSCmd.Add(14, mWash2_1);
        }
        /// <summary>
        /// 孵育小车复位
        /// </summary>
        public int IncubationReset()
        {
            SendCmd(0, mReset);
            Thread.Sleep(5);
            mStatus = -100;
            return 0;
        }
        /// <summary>
        /// 到试剂1
        /// </summary>
        public int R1()
        {
            SendCmd(1, mR1);
            mStatus = -1;
            return 1;
        }
        /// <summary>
        /// 到试剂1偏
        /// </summary>
        public int R1_1()
        {
            SendCmd(12, mR1_1);
            mStatus = -12;
            return 12;
        }
        /// <summary>
        /// 到试剂2
        /// </summary>
        public int R2()
        {
            SendCmd(2, mR2);
            mStatus = -2;
            return 2;
        }
        /// <summary>
        /// 到试剂2偏
        /// </summary>
        public int R2_1()
        {
            SendCmd(3,mR2_1);
            mStatus = -3;
            return 3;
        }
        /// <summary>
        /// 到清洗
        /// </summary>
        /// <param name="order">清洗位置1,2</param>
        public int Wash(int order)
        {
            if (order == 1)
            {
                SendCmd(4,mWash1);
                mStatus = -4;
                return 4;
            }
            else
            {
                SendCmd(13,mWash2);
                mStatus = -13;
                return 13;
            } 
        }
        /// <summary>
        /// 到清洗偏
        /// </summary>
        /// <param name="order">清洗位置1,2</param>
        public int Wash_1(int order)
        {
            if (order == 1)
            {
                SendCmd(5,mWash1_1);
                mStatus = -5;
                return 5;
            }
            else
            {
                SendCmd(14,mWash2_1);
                mStatus = -14;
                return 14;
            }
        }
        /// <summary>
        /// 到加底物
        /// </summary>
        public int Substrate()
        {
            SendCmd(6, mSubstrate);
            mStatus = -6;
            return 6;
        }
        /// <summary>
        /// 到加底物偏
        /// </summary>
        public int Substrate_1()
        {
            SendCmd(7, mSubstrate_1);
            mStatus = -7;
            return 7;
        }
        /// <summary>
        /// 到检测
        /// </summary>
        public int Detect()
        {
            SendCmd(8, mDetect);
            mStatus = -8;
            return 8;
        }
        /// <summary>
        /// 到检测偏
        /// </summary>
        public int Detect_1()
        {
            SendCmd(9, mDetect_1);
            mStatus = -9;
            return 9;
        }
        /// <summary>
        /// 放反应条 10
        /// </summary>
        /// <param name="seat"></param>
        public int DropStrip(int seat)
        {
            CmdModel _numberModel= EncordNum(seat);
            SendCmd(10, mDS).NumberCmd=_numberModel;
            mStatus = -10;
            return 10;
        }
        /// <summary>
        /// 取反应条 11
        /// </summary>
        /// <param name="seat"></param>
        public int GetStrip(int seat)
        {

            CmdModel _numberModel= EncordNum(seat);
            SendCmd(11, mGS).NumberCmd=_numberModel;
            mStatus = -11;
            return 11;
        }

        #endregion

      
    }
}
